package cdc.cs.controller;

import cdc.cs.common.JSONResult;
import cdc.cs.entity.TestBO;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("index")
public class TestController {

    @GetMapping("/1")
    public String index() {
        return 1/0 + "";
    }

    @GetMapping("/ob1/")
    public JSONResult getOne() {
        TestBO bo = new TestBO();
        bo.setId(110);
        bo.setName("赵灵儿");
        bo.setTitle("CEO");
        return JSONResult.ok(bo);
    }
    @GetMapping("/query/{id}")
    public JSONResult queryOne(@PathVariable @Valid Integer id) {
        if (id == null) {
            return JSONResult.errorMsg("id不存在");
        }
        TestBO bo = new TestBO();
        bo.setId(110);
        bo.setName("赵灵儿");
        bo.setTitle("CEO");
        return JSONResult.ok(bo);
    }

    @PostMapping("/add/one")
    public JSONResult addOne(@RequestBody @Valid TestBO bo) {
//        if (bo == null) {
//            return JSONResult.errorMsg("id不存在");
//        }
        System.out.println(bo);
        return JSONResult.ok();
    }
}
